<?php
/**
 * Address.php
 *
 * Niushop商城系统 - 团队十年电商经验汇集巨献!
 * =========================================================
 * Copy right 2015-2025 山西牛酷信息科技有限公司, 保留所有权利。
 * ----------------------------------------------
 * 官方网址: http://www.niushop.com.cn
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用。
 * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
 * =========================================================
 * @author : niuteam
 * @date : 2015.4.24
 * @version : v1.0.0.0
 */

namespace data\service;

/**
 * 区域地址
 */

use data\api\EnterpriseRegistration as IAddress;
use data\model\EnterpriseRegistration as Enter;
use data\service\BaseService as BaseService;
use think\cache\driver\Redis;

class EnterpriseRegistration extends BaseService implements IAddress
{

    private $enter;

    function __construct()
    {
        parent::__construct();
        $this->enter = new Enter();
    }

    /*
     * (non-PHPdoc)
     */
    public function addSettledIn($name,$phone, $desc, $address, $details, $operator,$loadPath,$businessLicence,$idCardBack,$idCardFrond,$type,$settledInType,$sms)
    {
        $redisKey = "_SMS".$phone;
        $reids = new Redis();
        $redis = $reids->get($redisKey);
        if(empty($redis)){
            $result['message'] = '验证码不存在';
            $result['status'] = false;
            return $result;
        }
        if($redis != $sms){
            $result['message'] = '验证码不正确';
            $result['status'] = false;
            return $result;
        }

        $data = array(
            'name' => $name,
            'phone'=>$phone,
            /* 'real_password' => $password, */
            'desc' => $desc,
            'address' => $address,
            'details' => $details,
            'operator' => $operator,
            'created_at' =>  time(),
            'updated_at' => time(),
            'image'=>$loadPath,
            'type'=>$type,
            'business_licence'=>$businessLicence,
            'id_card_back'=>$idCardBack,
            'id_card_front'=>$idCardFrond,
            'settled_in_type'=>$settledInType

        );
        $this->enter->save($data);
        $result['message'] = '入驻成功';
        $result['status'] = true;
        return $result;
    }


    public function getSettledQuery($condition,$page_size,$page_index,$order){

        $res = $this->enter->pageQuery($page_index, $page_size, $condition, $order, '*');
        return $res;
    }

    /**
     * @param $id
     */
    public function saveSettledIn($id,$status,$reject_info){
        $result_id = $this->enter->save(['status' => $status,'updated_at'=>time(),'reject_details' => $reject_info], [
            "id" => $id
        ]);
        return $result_id;
    }

    public function findSettle($condition){
        $info =$this->enter->getInfo($condition, '*');

        return $info;
    }

}